<?php
namespace Wap\Controller;
use Think\Controller;
use Think\Model;
use Think\Log;

use Wap\Service\UploadService;
use Wap\Service\SessionService;
use Wap\Service\CookieService;

class UploadController extends Controller
{
	public function index()
	{
		$this->display( "attend" );
	}

	public function file_pic()//上传作品
	{
		$file	=	UploadService::fetch_upload_file();
		$this->ajaxReturn( $file );
	}	

	public function  file_birth()//上传出生证明
	{
	}

    public function upload_file()

    {

        $files = $_FILES['myFile'];
        // 判断错误号

        if (@$files['error'] == 00) {

            // 判断文件类型

            $ext = strtolower(pathinfo(@$files['name'],PATHINFO_EXTENSION));

            if (!in_array($ext,['mp4', 'mov'])){

                echo "非法文件类型";

            }

            // 判断是否存在上传到的目录

            if (!is_dir("./Public/Uploads/meeting/")){

                mkdir("./Public/Uploads/meeting/",0777,true);

            }

            // 生成唯一的文件名

            $fileName = md5(uniqid(microtime(true),true)).'.'.$ext;

            // 将文件名拼接到指定的目录下

            $destName = "./Public/Uploads/meeting/" . $fileName;

            // 进行文件移动

            if (!move_uploaded_file($files['tmp_name'],$destName)){

                echo '';

            }

            echo substr($destName, 1);

        } else {

            // 根据错误号返回提示信息

            switch (@$files['error']) {

                case 1:

                    echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值";

                    break;

                case 2:

                    echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";

                    break;

                case 3:

                    echo "文件只有部分被上传";

                    break;

                case 4:

                    echo "没有文件被上传";

                    break;

                case 6:

                case 7:

                    echo "系统错误";

                    break;

            }
            echo '';
        }

    }
}
?>
